package com.feihong.txgw.tx_precenter;

import com.feihong.txgw.inter.contract.product.IProDetailContract;
import com.feihong.txgw.json.goodsCart.GoodsCartParser;
import com.feihong.txgw.model.greendao.ShopCarGoodsModel;
import com.feihong.txgw.tx_model.ProDetailModel;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * @Author wangziheng
 * @ProjectName txgw_app
 * @ClassName ProDetailMainPrecenter
 * @package com.feihong.txgw.tx_precenter
 * @data 2018/5/8 12:04
 * @Describe
 * @Change
 */
public class ProDetailMainPrecenter extends IProDetailContract.AbProDetailMainPrecenter {
    @Override
    public void addGoodsToShopCar(List<ShopCarGoodsModel> goodsModels) {
        mIModel.addGoodsToShopCar(goodsModels).subscribe(new Observer<GoodsCartParser>() {
            @Override
            public void onSubscribe(Disposable d) {
                mRxManager.register(d);
            }

            @Override
            public void onNext(GoodsCartParser goodsCartParser) {
                mIView.addGoodsToShopCarResult(goodsCartParser);
            }

            @Override
            public void onError(Throwable e) {
                mIView.loadDataError();
            }

            @Override
            public void onComplete() {

            }
        });
    }

    @Override
    public IProDetailContract.IProDetailMainModel getModel() {
        return ProDetailModel.create();
    }

    public static ProDetailMainPrecenter create(){
        return new ProDetailMainPrecenter();
    }
    @Override
    public void onStart() {

    }
}
